import 'package:flutter/material.dart';

class CheckBoxAndRadioAndSwitchPage extends StatefulWidget {
  final Map<String, dynamic> arguments;
  CheckBoxAndRadioAndSwitchPage({Key key, this.arguments}) : super(key: key);

  @override
  _CheckBoxAndRadioAndSwitchPageState createState() => _CheckBoxAndRadioAndSwitchPageState();
}

enum TasteOfSpicy {
  slightly_spicy,
  medium_spicy,
  super_spicy,
}

class _CheckBoxAndRadioAndSwitchPageState extends State<CheckBoxAndRadioAndSwitchPage> {
  var _is18 = false;
  var _accept = false;
  var _sex = 'Male';
  var _taste = TasteOfSpicy.medium_spicy;
  var _useApplePay = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        child: AppBar(
          backgroundColor: Colors.red,
          title: Text('CheckBoxAndRadioAndSwitchPage'),
        ),
        preferredSize: Size.fromHeight(44.0),
      ),
      body: ListView(
        children: <Widget>[
          Container(
            child: Row(
              children: <Widget>[
                Checkbox(
                  value: this._is18,
                  activeColor: Colors.red,
                  checkColor: Colors.yellow,
                  onChanged: (value) {
                    setState(() {
                      this._is18 = value;
                    });
                  },
                ),
                Text('已满18'),
              ],
            ),
          ),
          Divider(height: 1.0),
          CheckboxListTile(
            value: this._accept,
            title: Text('用户协议'),
            subtitle: Text(
              '用户在使用技术开发方（即，以下统称“技术开发方”）提供的各项服务之前，应仔细阅读本《用户协议》（以下简称“本协议”）。用户一旦登录或使用技术开发方的服务，即视为用户已了解并明示同意本协议各项内容，本协议立即在用户与本技术开发方之间产生法律效力。用户登录、使用本产品服务的全部活动将受到本协议的约束并承担相应的责任和义务。',
              maxLines: 4,
              overflow: TextOverflow.ellipsis,
            ),
            controlAffinity: ListTileControlAffinity.leading,
            onChanged: (value) {
              setState(() {
                this._accept = value;
              });
            },
            selected: this._accept,
            secondary: Icon(Icons.people),
          ),
          Divider(height: 1.0),
          Row(
            children: <Widget>[
              Radio(
                value: 'Male',
                groupValue: this._sex,
                onChanged: (value) {
                  setState(() {
                    this._sex = value;
                  });
                },
              ),
              Text('男'),
              SizedBox(width: 20.0),
              Radio(
                value: 'Female',
                groupValue: this._sex,
                onChanged: (value) {
                  setState(() {
                    this._sex = value;
                  });
                },
              ),
              Text('女'),
            ],
          ),
          Divider(height: 1.0),
          Column(
            children: <Widget>[
              RadioListTile(
                value: TasteOfSpicy.slightly_spicy,
                title: Text('微辣'),
                subtitle: Text('🌶'),
                activeColor: Colors.red,
                groupValue: this._taste,
                selected: this._taste == TasteOfSpicy.slightly_spicy,
                onChanged: (value) {
                  setState(() {
                    this._taste = value;
                  });
                },
                secondary: Image.network('http://5b0988e595225.cdn.sohucs.com/images/20171105/d7d221a295de48999d5b05d3755643a2.jpeg'),
              ),
              Divider(height: 1.0, indent: 20.0),
              RadioListTile(
                value: TasteOfSpicy.medium_spicy,
                title: Text('中辣'),
                subtitle: Text('🌶🌶'),
                activeColor: Colors.red,
                groupValue: this._taste,
                selected: this._taste == TasteOfSpicy.medium_spicy,
                onChanged: (value) {
                  setState(() {
                    this._taste = value;
                  });
                },
                secondary: Image.network('http://5b0988e595225.cdn.sohucs.com/images/20180212/f5c7c908769543e09ec75dde8ea393f8.jpeg'),
              ),
              Divider(height: 1.0, indent: 20.0),
              RadioListTile(
                value: TasteOfSpicy.super_spicy,
                title: Text('超级辣'),
                subtitle: Text('🌶🌶🌶'),
                activeColor: Colors.red,
                groupValue: this._taste,
                selected: this._taste == TasteOfSpicy.super_spicy,
                onChanged: (value) {
                  setState(() {
                    this._taste = value;
                  });
                },
                secondary: Image.network('http://5b0988e595225.cdn.sohucs.com/images/20180423/6e9548c5140b494e81f478bbdff44e5e.jpeg'),
              ),
            ],
          ),
          Divider(height: 1.0),
          Container(
            padding: EdgeInsets.only(left: 15.0, right: 15.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text('Use Apple Pay', style: TextStyle(fontWeight: FontWeight.bold)),
                Container(
                  width: 60.0,
                  child: Switch(
                    value: this._useApplePay,
                    onChanged: (value) {
                      setState(() {
                        this._useApplePay = value;
                      });
                    },
                  ),
                ),
              ],
            ),
          ),
          Divider(height: 1.0),
        ],
      ),
    );
  }
}
